package jpa;


import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

/*
public class FileUploadServlet extends HttpServlet 
{
    private static final String UPLOAD_DIRECTORY = "";
    private static final int THRESHOLD_SIZE = 1024 * 1024 * 3; // 3MB
    private static final int MAX_FILE_SIZE = 1024 * 1024 * 40; // 40MB
    private static final int REQUEST_SIZE = 1024 * 1024 * 50; // 50MB
/*
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
    {
    

    protected void doPost(HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException, IOException 
    {
        
        response.setContentType("text/html;charset=UTF-8");

        String relativeWebPath = "/images/";
        String absoluteDiskPath = getServletContext().getRealPath(relativeWebPath);
        final String path = absoluteDiskPath;
        
        Part filePart = request.getPart("file");
        final String fileName = getFileName(filePart);

        OutputStream out = null;
        InputStream filecontent = null;
        final PrintWriter writer = response.getWriter();

        try 
        {
            out = new FileOutputStream(new File(path + File.separator
                    + fileName));
            filecontent = filePart.getInputStream();

            int read = 0;
            final byte[] bytes = new byte[1024];

            while ((read = filecontent.read(bytes)) != -1) 
            {
                out.write(bytes, 0, read);
            }
            writer.println("New file " + fileName + " created at " + path);
        } 
        catch (FileNotFoundException fne) 
        {
            writer.println("You either did not specify a file to upload or are "
                    + "trying to upload a file to a protected or nonexistent "
                    + "location.");
            writer.println("<br/> ERROR: " + fne.getMessage());
        } 
        finally 
        {
            if (out != null) 
            {
                out.close();
            }
            if (filecontent != null) 
            {
                filecontent.close();
            }
            if (writer != null) 
            {
                writer.close();
            }
        }
    }

    private String getFileName(final Part part) 
    {
        for (String content : part.getHeader("content-disposition").split(";")) 
        {
            if (content.trim().startsWith("filename")) 
            {
                return content.substring(
                        content.indexOf('=') + 1).trim().replace("\"", "");
            }
        }
        return null;
    }

}
    */